package com.itheima.homework5;

import java.util.concurrent.Callable;

public class StoreHouse {
    private int cap ;

    public StoreHouse(int cap) {
        this.cap = cap;
    }
    public synchronized void store(){
        while (cap >= 10){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        cap++;
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"存入1个单位货物，现在仓库剩余"+ cap);
        notifyAll();
    }
    public synchronized void get(){
        while (cap<=0){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        cap--;
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"消费取出1个单位货物，现在仓库剩余"+cap);
        notifyAll();
    }
}
